import React from 'react'
// BrowserRouter = Router +
import { Router, Route, Redirect, Switch } from 'react-router-dom'
import AuthRoute from './components/AuthRoute'
import Loading from './components/Loading'
// import Layout from './pages/Layout'
// import Login from './pages/Login'
// const NotFound = React.lazy(() => import('./pages/NotFound'))
import Test from './pages/Test'
import history from './utils/history'
const Layout = React.lazy(() => import('./pages/Layout'))
const Login = React.lazy(() => import('./pages/Login'))
const NotFound = React.lazy(() => import('./pages/NotFound'))
const ProfileEdit = React.lazy(() => import('./pages/Profile/Edit'))
const ProfileChat = React.lazy(() => import('./pages/Profile/Chat'))

export default function App() {
  return (
    <div>
      <Router history={history}>
        <React.Suspense fallback={<Loading />}>
          <Switch>
            {/* 重定向，需要 exact 指定精确匹配 */}
            <Redirect exact path="/" to="/home" />
            <Route path="/home" component={Layout} />
            {/* 不需要 tabBar 的页面 */}
            <Route path="/login" component={Login} />
            <AuthRoute path="/profile/edit" component={ProfileEdit} />
            <AuthRoute path="/profile/chat" component={ProfileChat} />
            {/* 测试页面 */}
            <Route path="/test" component={Test} />
            {/* 404 页面 */}
            <Route path="*" component={NotFound} />
          </Switch>
        </React.Suspense>
      </Router>
    </div>
  )
}
